package com.eureka.bclass.util;

import java.text.MessageFormat;

/**
 * @Description: 数字转化
 * @Author: lixing
 * @Date: 2021/6/23 16:37
 */
public class NumUtil {
    public static void main(String[] args) {
        System.out.println(formate(1));
        System.out.println(formate(9999));
        System.out.println(formate(10000));
        System.out.println(formate(10999));
        System.out.println(formate(11000));
        System.out.println(formate(11001));
        System.out.println(formate(12000));
        System.out.println(formate(12999));
        System.out.println(formate(20000));
    }
    /**
     * @Description 格式化
     */
    public static String formate(long num) {
        if (num < 10000) {
            return String.valueOf(num);
        }
        long wangUnit = num / 10000;
        long qianUnit = num % 10000 / 1000;
        String result = MessageFormat.format("{0}.{1}万", wangUnit, qianUnit);
        result = result.replace(".0", "");
        return result;
    }
}
